﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using Microsoft.Win32;

namespace sms_modem_control
{
    public partial class frmSystemMonitor : Form
    {
        RegistryKey Rkey;
        private SystemUtilities usage ;
        Process currentProc;
        string strInfor;
        string strInfortmp;
        public frmSystemMonitor()
        {
            InitializeComponent();
             Rkey = Registry.LocalMachine;
               usage = new SystemUtilities();
            currentProc = Process.GetCurrentProcess();
            
        }

        private void timeMonitor_Tick(object sender, EventArgs e)
        {
            short cpuUsage = usage.GetUsage();
            lblCPUUsage.Text = "CPU usage: " + cpuUsage+" %";
            lblRAMUsage.Text = "RAM usage: " + (currentProc.PrivateMemorySize64 / 1024) + " kb";
            //
            strInfortmp ="\nTotal time start: "+ ((System.Environment.TickCount / 1000) / 60) + "  Minute(s)";

            lblSystemInfor.Text = strInfor + strInfortmp;
            strInfortmp = "";
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmSystemMonitor_Load(object sender, EventArgs e)
        {
            try
            {
                Rkey = Rkey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
                strInfor = "CPU: " + (string)Rkey.GetValue("ProcessorNameString");
                strInfor += "\nNumber of processor: " + System.Environment.ProcessorCount;
                strInfor += "\nMemory mapped to the process context: " + System.Environment.WorkingSet / 1024 + " kb";
                Rkey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\BIOS");
                strInfor += "\nSystem Manufacturer: " + (string)Rkey.GetValue("SystemManufacturer");
                strInfor += "\nSystem ProductName: " + (string)Rkey.GetValue("SystemProductName");
    
                Rkey.Close();
                //strInfor += "\n" + SystemInformation.PrimaryMonitorSize.ToString();
                //strInfor += "\nOS version: " + System.Environment.OSVersion.ToString();
                //strInfor += "\nMachine name: " + System.Environment.MachineName;
                //strInfor += "\nUser Domain name: " + System.Environment.UserDomainName;
                //strInfor += "\nUser name: " + System.Environment.UserName;
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
